package top.huiwow.entity;

import org.bukkit.Location;
import top.huiwow.GameCore;

import java.util.HashMap;
import java.util.Map;

public class EntityManager {
    public Map<Integer, AkaishiEntity> registeredEntities = new HashMap<>();

    public void registerEntity(AkaishiEntity... e) {
        for (AkaishiEntity ent : e) {
            ent.setInternalID(registeredEntities.size());
            GameCore.getInstance().registerEvent(ent);
            registeredEntities.put(registeredEntities.size(), ent);
        }
    }

    public int getInternalID(Class<? extends AkaishiEntity> e) {

        for (int i = 0; i < registeredEntities.size(); i++) {
            if (registeredEntities.get(i).getClass().getName().equals(e.getName())) {
                return i;
            }
        }
        throw new RuntimeException("CANNOT FIND YOUR ENTITY ID?MAYBE IT IS NOT REGISTERED.");
    }

    public void spawnEntity(Location location, int id, int level) {
        registeredEntities.get(id).spawn(location, level);
    }
}
